package com.gdpa.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gdpa.entity.SaleArea;
import com.gdpa.entity.vo.ResponseData;
import com.gdpa.service.ISaleAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * 出售区域表 前端控制器
 * </p>
 *
 * @author zsr
 * @since 2018-12-19
 */
@RestController
@RequestMapping("/sale-area")
public class SaleAreaController {

    @Autowired
    ISaleAreaService saleAreaService;
    HttpServletRequest request;
    HttpSession session;


    @RequestMapping("/list")
    public ResponseData list(Page page,@RequestParam(value = "search",required = false)String search){
        List<SaleArea> saleAreaList = saleAreaService.search(page,search);
        return ResponseData.okPage(page.getTotal() ,saleAreaList);
    }

    @RequestMapping("/save")
    public ResponseData save(SaleArea saleArea){
        boolean flg = saleAreaService.save(saleArea);
        if (flg){
            return ResponseData.okMsg("添加成功！！");
        }else {
            return ResponseData.failMsg("添加失败！！");
        }
    }

    @RequestMapping("/edit")
    public ResponseData edit(SaleArea saleArea){
        boolean flg = saleAreaService.edit(saleArea);
        if (flg){
            return ResponseData.okMsg("修改成功！！");
        }else {
            return ResponseData.failMsg("修改失败！！");
        }
    }

    @RequestMapping("/delete")
    public ResponseData delete(Integer saleAreaId){
        boolean flg = saleAreaService.delete(saleAreaId);
        if (flg){
            return ResponseData.okMsg("删除成功！！");
        }else {
            return ResponseData.failMsg("删除失败！！");
        }
    }


}
